/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable import/no-extraneous-dependencies */

import gulp from 'gulp';
import ts from 'gulp-typescript';
import uglify from 'gulp-uglify-es';
import babel from 'gulp-babel';

const clean = require('gulp-clean');

const tsProject = ts.createProject('tsconfig.json');
tsProject.config.include = ['src'];

gulp.task('clean', () => gulp.src('build', { allowEmpty: true }).pipe(clean()));

gulp.task('tsc', () => {
  const tscFiles = tsProject.src().pipe(tsProject());
  tscFiles.js.pipe(babel()).pipe(uglify()).pipe(gulp.dest('build'));
  tscFiles.dts.pipe(gulp.dest('build'));
  return tscFiles;
});

gulp.task('default', gulp.series(['clean', 'tsc']));
